package com.atguigu.srb.sms.controller;


import com.atguigu.srb.common.exception.Assert;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.common.result.ResponseEnum;
import com.atguigu.srb.sms.client.CoreUserInfoClient;
import com.atguigu.srb.sms.service.SmsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sms")
@Api(tags = "短信管理")
@Slf4j
@CrossOrigin
public class ApiSmsController {

    @Autowired
    SmsService smsService;

    @Autowired
    CoreUserInfoClient coreUserInfoClient;

    @GetMapping("sendCode/{mobile}")
    public R sendCode(@PathVariable String mobile){
        // 先判断手机号是否已经注册过
        boolean mobileExist = coreUserInfoClient.isMobileExist(mobile);
        Assert.isTrue(!mobileExist, ResponseEnum.MOBILE_EXIST_ERROR);
        smsService.sendCode(mobile);
        return R.OK();
    }
}